home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 1 / Precision Software Applications Silver Collection Volume One (PSM) (1993).iso / windows / games / iconan.exe / ICONANM.C < prev    next >
C/C++ Source or Header  |  1988-03-17  |  3KB  |  120 lines

  1. /* IconAnm.C -- Windows application that displays 
  2.  * an animated icon by Tony Vollmer for SDK 2.00 */
  3.  
  4. #include <windows.h>    /* all Windows functions */
  5.  
  6. long FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  7.  
  8. HANDLE hInst; /* save for SetClassWord and GetClassWord */
  9. int nIcon;   /* save current icon resource number */
  10.  
  11. /* WinMain - Main loop for all Windows applications */
  12. int PASCAL WinMain (hInstance,
  13.                     hPrevInstance,
  14.                     lpszCmdLine, 
  15.                     nCmdShow)
  16. HANDLE  hInstance, hPrevInstance;
  17. LPSTR   lpszCmdLine;
  18. int     nCmdShow;
  19. {
  20.     static   char szAppName [] = "IconAnm";
  21.     WNDCLASS WndClass;
  22.     HWND     hWnd;
  23.     MSG      msg;
  24.  
  25.     /* allow only one instance */
  26.     if (hPrevInstance)
  27.        return FALSE;
  28.  
  29.     /* Save hInstance */
  30.     hInst = hInstance;
  31.     nIcon = 1000;
  32.     /* define Window class */
  33.     WndClass.hCursor       = NULL;
  34.     WndClass.hIcon         = LoadIcon(hInstance,
  35.                              MAKEINTRESOURCE(nIcon));
  36.     WndClass.cbClsExtra    = 0;
  37.     WndClass.cbWndExtra    = 0;
  38.     WndClass.lpszMenuName  = NULL;
  39.     WndClass.lpszClassName = (LPSTR) szAppName;
  40.     WndClass.hbrBackground = COLOR_WINDOW + 1;
  41.     WndClass.hInstance     = hInstance;
  42.     WndClass.style         = CS_VREDRAW | CS_HREDRAW;
  43.     WndClass.lpfnWndProc   = WndProc;
  44.  
  45.     /* register this new class with WINDOWS */
  46.     if (!RegisterClass((LPWNDCLASS)&WndClass))
  47.        return FALSE;   /* Initialization failed */
  48.  
  49.     /* create window */
  50.     hWnd = CreateWindow((LPSTR) szAppName,
  51.             (LPSTR)  NULL,
  52.             WS_OVERLAPPEDWINDOW,
  53.             CW_USEDEFAULT,
  54.             0,
  55.             0,
  56.             CW_USEDEFAULT,
  57.             (HWND)   NULL,
  58.             (HMENU)  NULL,
  59.             hInstance,
  60.             (LPSTR)  NULL);
  61.  
  62.     /* set up timer (10 updates/sec) */
  63.     if (!SetTimer (hWnd, 1, 100, NULL) )
  64.     {
  65.        MessageBox(hWnd,
  66.                   (LPSTR)"Too Many Timers!",
  67.                   (LPSTR)szAppName,
  68.                   MB_ICONEXCLAMATION | MB_OK);
  69.        return FALSE;
  70.     }
  71.  
  72.     /* show window (start in ICONIC state) */
  73.     ShowWindow( hWnd, SW_SHOWMINNOACTIVE );
  74.     UpdateWindow( hWnd );
  75.  
  76.     /* main program loop */
  77.     while (GetMessage ((LPMSG) &msg, NULL, 0, 0)) {
  78.        TranslateMessage((LPMSG) &msg );
  79.        DispatchMessage((LPMSG) &msg );
  80.     } /* end while GetMessage */
  81.  
  82.     /* exit back to Windows */
  83.     return (int) msg.wParam;
  84.  
  85. } /* end WinMain */
  86.  
  87. /* WndProc - Window procedure for main window */
  88. long FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  89. HWND    hWnd;
  90. unsigned message;
  91. WORD    wParam;
  92. LONG    lParam;
  93. {
  94.  
  95.     /* switch on message type sent to window by Windows dispatcher */
  96.     switch(message) {
  97.        case WM_TIMER:
  98.           /* change icon between 1000, 1001, 1002, 1003 */
  99.           nIcon = ((++nIcon-1000) % 4) + 1000;
  100.           SetClassWord(hWnd,
  101.                GCW_HICON,
  102.                LoadIcon(hInst,MAKEINTRESOURCE(nIcon)));
  103.           InvalidateRect(hWnd,NULL,TRUE);
  104.           UpdateWindow(hWnd);
  105.           break;
  106.        case WM_QUERYOPEN:
  107.           /* prevent opening of icon */
  108.           break;
  109.        case WM_DESTROY:
  110.           KillTimer (hWnd, 1);
  111.           PostQuitMessage( 0 );
  112.           break;
  113.        default:
  114.           return DefWindowProc( hWnd, message, wParam, lParam);
  115.     } /* end switch */
  116.  
  117.     return (long) 0;
  118.  
  119. } /* end WndProc */
  120.